<?php defined('SYSPATH') or die('No direct script access.');

/**
 * Created by PhpStorm.
 * Author: ls
 * Time: 2020/10/23 14:19
 * Desc: 问答功能
 */
class Controller_Pc_Api_V2_Question extends Controller_Pc_Api_v2_Base
{

    // 数据请求结果
    private $result;

    /**
     * 参数验证对象
     * @var Request_Api_V2_Question
     */
    private $validation;

    /**
     * 服务
     * @var Service_Api_Question
     */
    private $service;

    public function before()
    {
        parent::before();

        // 验证
        $this->validation = Request_Api_V2_Factory::create('question', $this->request_params);

        // 服务
        $this->service = new Service_Api_Question();

        // 返回数据
        $this->result = array('status' => true, 'msg' => '操作成功', 'data' => array());
    }

    public function after()
    {
        $this->send_datagrams($this->client_info['id'], $this->result, $this->client_info['secret_key']);
    }

    // 获取问答数据
    public function action_question_list()
    {
        try {
            $this->validation->question_list()->check();

            $this->result['data'] = $this->service->question_list($this->request_params);
        } catch (Exception $e) {
            $this->result['status'] = false;
            $this->result['msg']    = $e->getMessage();
        }
    }


    //提问功能提交
    public function action_add_question()
    {
        try {
            $this->validation->add_question()->check();

            $this->result['data'] = $this->service->add_question($this->request_params);
            $this->result['msg'] = '提交成功，等待回复';
        } catch (Exception $e) {
            $this->result['status'] = false;
            $this->result['msg']    = $e->getMessage();
        }
    }

}